package com.adcc.msgsimulator.task;

import com.adcc.msgsimulator.service.Msg618Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author a123
 */
@Component
@EnableScheduling
@Slf4j
public class Msg618Task {
    @Autowired
    private Msg618Service msg618Service;
    public static final String DWON = "dwon";
    public static final String UP = "up";

    @Scheduled(cron = "${scheduled.cron}")
    @Async(value = "threadPoolTaskExecutor")
    public void downask() {
        log.info(Thread.currentThread().getName());
        synchronized (DWON) {
            try {
                log.info("select downlink start");
                msg618Service.selectDownLink();
                log.info("select downlink end");
            } catch (Exception ex) {
                log.error("downTask() error", ex);
            }
        }
    }

    @Scheduled(cron = "${scheduled.cron}")
    @Async(value = "threadPoolTaskExecutor")
    public void upTask() {
        log.info(Thread.currentThread().getName());
        synchronized (UP) {
            try {
                log.info("select uplink start");
                msg618Service.selectUpLink();
                log.info("select uplink end");
            } catch (Exception ex) {
                log.error("upTask() error", ex);
            }
        }
    }

}
